package cn.rocky.offer;

/**
 * 长度为n的绳子,请把绳子剪成整数长度的m段,乘积最大
 */
public class offer14I {

    /**
     * @param n 绳子长度
     * @return 返回最大乘积
     */
    public int cuttingRope(int n) {
        int[] dp = new int[n + 1];
        dp[2] = 1;
        for (int i = 3; i < n + 1; i++) {
            for (int j = 2; j < i; j++) {
                dp[i] = Math.max(dp[i], Math.max(j * (i - j), j * dp[i - j]));
            }
        }
        return dp[n];
    }


    public static void main(String[] args) {
        offer14I offer14I = new offer14I();
        int i = offer14I.cuttingRope(8);
        System.out.println(i);
    }
}
